<?php
namespace Application\Model;

use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql;
use Zend\Db\Sql\Where;
use Zend\Db\Sql\Select;
use Zend\Paginator\Adapter\DbSelect;
use Zend\Paginator\Paginator;
class PendingmailTable
{
    protected $tableGateway;
	protected $select;
    public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
		$this->select = new Select();
    }
	public function addMail($subject,$message,$to_mail,$to_from)
    {		
		$data = array(			
			'subject' 	=> $subject, 
			'content' 	=> $message,			
			'to_mail'  	=> $to_mail, 
			'to_from'  	=> $to_from,
			'status'  	=> 1, 
		);				
		$this->tableGateway->insert($data);
		return $this->tableGateway->lastInsertValue;
    }	
	public function getpendingmails()
    {
		$select = $this->tableGateway->getSql()->select()
				->join('user', 'user.email=pendingmail.to_mail',array('*'),'left')
				->where(array('status' => 1));				
		$resultSet = $this->tableGateway->selectWith($select);	
		return $resultSet;
	}
	public function updatemailstatus($mail_ids)
    {
		//echo '<pre>';print_r($mail_ids);exit;
		$result=$this->tableGateway->update(array('status'=>'0'),array('mail_id'=>$mail_ids));
		return  $result;
	}
}